﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StockMaintain.aspx.cs" Inherits="H2.NET.Web.Pages.SMD.InStock.StockMaintain" %>
<%@ Import Namespace="H2.NET.Common" %>

<style type="text/css">
    .list input { width: 96%; }
    .list input.number { text-align: center; }
    .list input.readonly { text-align: right; }
    .list thead tr th { text-align:center; }
    .list tbody tr.title td { text-align:center;background: #eee; }
    .list tbody tr.items td { text-align:center;background: #fff; }
    .list tbody tr td.total { text-align:right; background: #eee; padding-right:5px; }
    .list tbody tr td.total span { font-style: italic;margin-right: 10px; }
</style>

<script type="text/javascript">
    $(':text.ci', $.pdialog.getCurrent()).focus(function () {
        var $a = $(this).val().replace(/,|\s/g, '');
        $(this).val($a);
    });
    $(':text.ci', $.pdialog.getCurrent()).blur(function () {
        var $b = fmoney($(this).val());
        $(this).val($b);
    });

    $(':text.ci,:text.number', $.pdialog.getCurrent()).keyup(function () {
        var money = $(this).parents("tr:first").find(".ci").val().replace(/,|\s/g, '');
        var num = $(this).parents("tr:first").find(".number").val();
        $(this).parents("tr:first").find("[readonly]").val(fmoney(money * num));

        var total = 0;
        $(":text[readonly='readonly']", $.pdialog.getCurrent()).each(function () {
            if ($(this).val() != "") {
                total += parseFloat($(this).val().replace(/,|\s/g, ''));
            }
        });
        $("#total", $.pdialog.getCurrent()).text(fmoney(total));
        $("#balance", $.pdialog.getCurrent()).text(fmoney(parseFloat($("#now", $.pdialog.getCurrent()).text().replace(/,|\s/g, '')) - total));
    });
    
    function roadDialog() {
        var area = escape($("#area", $.pdialog.getCurrent()).val());
        $.pdialog.reload("pages/smd/InStock/StockMaintain.aspx?area=" + area, { width: 860, height: 556, mask: true });
    }
</script>

<div class="pageContent">
    <form method="post" action="Pages/SMD/InStock/StockMaintain.aspx?action=save" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
    <div class="pageFormContent" layoutH="40" style="padding:0;">
        <p>
            <label style="width:auto;">地区：</label>
            <select id="area" name="area" onchange="roadDialog()">
                <option value="上海" <%=AksRequest.GetString("area") == "上海" ? "selected" : ""%>>上海</option>
                <option value="广州" <%=AksRequest.GetString("area") == "广州" ? "selected" : ""%>>广州</option>
                <option value="廊坊" <%=AksRequest.GetString("area") == "廊坊" ? "selected" : ""%>>廊坊</option>
            </select>
        </p>
        <table class="list" style="width:100%;">
            <thead>
                <tr>
                    <th style="width:10%;">设备分类</th>
                    <th style="width:10%;">设备型号</th>
                    <th style="width:10%;">现有库存</th>
                    <th style="width:15%;">设备单价</th>
                    <th style="width:15%;">采购数量</th>
                    <th style="width:15%;">采购价</th>
                    <th style="width:25%;">备注</th>
                </tr>
            </thead>
            <tbody>
                <asp:Repeater id="rpt_model" runat="server" OnItemDataBound="rpt_model_ItemDataBound"><ItemTemplate>
                <tr class="title">
                    <td style="text-align:left;"><%#Eval("value")%></td>
                    <td colspan="7"><input type="hidden" runat="server" id="h_code" value='<%#Eval("key")%>' /></td>
                </tr>
                    <asp:Repeater id="rpt_items" runat="server"><ItemTemplate>
                    <tr class="items">
                        <td><input type="hidden" name='id_<%#Eval("Code")%>' value='<%#Eval("id")%>' /></td>
                        <td style="text-align:left;"><%#Eval("Name")%></td>
                        <td><%#Utils.StrToInt(Eval("InitQuantity").ToString(), 0) - Utils.StrToInt(Eval("SendQuantity").ToString(), 0)%></td>
                        <td><input type="text" class="ci" name='Price_<%#Eval("Code")%>' value='<%#Utils.StrToDecimal(Eval("Price").ToString(), 0).ToString("N")%>' /></td>
                        <td><input type="text" class="number" name='Number_<%#Eval("Code")%>' /></td>
                        <td><input type="text" readonly="readonly" name='Amount_<%#Eval("Code")%>' /></td>
                        <td><input type="text" name='Remark_<%#Eval("Code")%>' value='<%#Eval("Remark")%>' /></td>
                    </tr>
                    </ItemTemplate></asp:Repeater>
                </ItemTemplate></asp:Repeater>
                <tr>
                    <td colspan="7" class="total">
                        现有预算：<span id="now"><%=BalanceBudget%></span>
                        本次采购总价：<span id="total">0.00</span>
                        预算余额：<span id="balance">0.00</span>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
	<div class="formBar">
		<ul>
			<li><div class="buttonActive"><div class="buttonContent"><button type="submit">提交数据</button></div></div></li>
			<li><div class="button"><div class="buttonContent"><button type="button" class="close">关闭窗体</button></div></div></li>
		</ul>
	</div>
    </form>
</div>